package cn.jy.authority.controller;

import cn.jy.authority.service.IExpressageRoleService;
import cn.jy.common.authority.ExpressageRole;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/role")
public class ExpressageRoleController extends BaseController
{
    @Autowired
    private IExpressageRoleService expressageRoleService;

    /**
     * 查询角色管理列表
     */
//    @RequiresPermissions("system:role:list")
    @GetMapping("/list")
    public TableDataInfo list(ExpressageRole expressageRole)
    {
        startPage();
        List<ExpressageRole> list = expressageRoleService.selectExpressageRoleList(expressageRole);
        return getDataTable(list);
    }

    /**
     * 导出角色管理列表
     */
//    @RequiresPermissions("system:role:export")
    @Log(title = "角色管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExpressageRole expressageRole)
    {
        List<ExpressageRole> list = expressageRoleService.selectExpressageRoleList(expressageRole);
        ExcelUtil<ExpressageRole> util = new ExcelUtil<ExpressageRole>(ExpressageRole.class);
        util.exportExcel(response, list, "角色管理数据");
    }

    /**
     * 获取角色管理详细信息
     */
//    @RequiresPermissions("system:role:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(expressageRoleService.selectExpressageRoleById(id));
    }

    /**
     * 新增角色管理
     */
//    @RequiresPermissions("system:role:add")
    @Log(title = "角色管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExpressageRole expressageRole)
    {
        return toAjax(expressageRoleService.insertExpressageRole(expressageRole));
    }

    /**
     * 修改角色管理
     */
//    @RequiresPermissions("system:role:edit")
    @Log(title = "角色管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExpressageRole expressageRole)
    {
        return toAjax(expressageRoleService.updateExpressageRole(expressageRole));
    }

    /**
     * 删除角色管理
     */
//    @RequiresPermissions("system:role:remove")
    @Log(title = "角色管理", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(expressageRoleService.deleteExpressageRoleByIds(ids));
    }
}
